package com.ruoyi.activiti;

import com.ruoyi.common.security.annotation.EnableCustomConfig;
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 代码生成
 *
 * @author ruoyi
 */
@EnableCustomConfig
@EnableCustomSwagger2
@EnableRyFeignClients
@RestController
@SpringBootApplication(exclude = {
        DataSourceAutoConfiguration.class
        ,org.activiti.spring.boot.SecurityAutoConfiguration.class
        //,org.activiti.spring.boot.DataSourceProcessEngineAutoConfiguration.class
})
public class RuoYiActivitiApplication {
    public static void main(String[] args) {
        ConfigurableApplicationContext application = SpringApplication.run(RuoYiActivitiApplication.class, args);
        Environment env = application.getEnvironment();
        System.out.println(buildWelcome(env));
    }

    private static String buildWelcome(Environment env){
        String ip = "localhost";
        try {
            ip = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
        }
        String port = env.getProperty("server.port");
        String name = env.getProperty("spring.application.name");
        String desc = env.getProperty("spring.application.desc");
        return "\n----------------------------------------------------------\n" +
                "\t"+name+" 启动完成。\n" +
                "\tLocal:\t\thttp://"+ip+":" + port + "/\n" +
                "\t文档:\t\thttp://" + ip + ":" + port + "/doc.html\n" +
                "\t描述:\t\t"+desc+"\n" +
                "----------------------------------------------------------";
    }

    @Autowired
    private Environment environment;

    @GetMapping
    public String index(){
        return buildWelcome(environment);
    }
}
